package com.gs2.servlet;
import java.io.IOException;
import java.util.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.*;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

public class CommandServlet extends javax.servlet.http.HttpServlet 
{

	public void doGet(
			javax.servlet.http.HttpServletRequest request,
			javax.servlet.http.HttpServletResponse response)
			throws javax.servlet.ServletException
		{
			performTask(request,response);
		}
	
	public void doPost(
			javax.servlet.http.HttpServletRequest request,
			javax.servlet.http.HttpServletResponse response)
			throws javax.servlet.ServletException
		{
			performTask(request, response);
		}
	
	public void performTask(
			javax.servlet.http.HttpServletRequest request,
			javax.servlet.http.HttpServletResponse response)
	{
		
		String action = (String)request.getParameter("action");
		
		MailCenter mailCenter = null;
		mailCenter = new MailCenter("mail.visionmax.com", "rohit@visionmax.com", "rohit@visionmax.com");
		mailCenter.setMimeType("text/html");
		String emailSubject = "";
		String emailContent = "";

		
		if (action.equals("askprepskills"))
		{
			emailSubject = "Ask Prepskills";
			emailContent = buildAskPrepskillsContent(emailContent);
		}
		
		try {
			mailCenter.sendMail(emailSubject, emailContent, null, null);
		} catch (AddressException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MessagingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		if (action.equals("askprepskills"))
		{
			try {
				response.sendRedirect("/GeneralWeb/askprepskills.tiles");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	}
	
	public String buildAskPrepskillsContent (String content)
	{
		return "Need formatting for the text and sample forms";
	}

}